package com.wing.product.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.common.utils.JsonResult;
import com.wing.product.dao.WarehouseProductVarietyDao;
import com.wing.product.model.entity.WarehouseProductVariety;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WarehouseProductVarietyServiceImpl extends ServiceImpl<WarehouseProductVarietyDao, WarehouseProductVariety> implements WarehouseProductVarietyService{

    @Override
    public Page<WarehouseProductVariety> pageList4app(Page page, Map<String, Object> params) {
        List<WarehouseProductVariety> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public JsonResult saveWarehouseProductVariety(WarehouseProductVariety warehouseProductVariety) {
        JsonResult jsonResult = new JsonResult<>();
        if (ObjectUtil.isNotEmpty(warehouseProductVariety)){
//        WarehouseProductVariety warehouseProductVariety = new WarehouseProductVariety();
//        CopyOptions copyOptions = CopyOptions.create()
//                .setEditable(WarehouseProductVariety.class)
//                .setIgnoreError(true)
//                .setIgnoreNullValue(true);
//        BeanUtil.copyProperties(warehouseProductVarietyForm, warehouseProductVariety,copyOptions);
        baseMapper.insert(warehouseProductVariety);
            return jsonResult.success("添加成功");
        }else {
            return jsonResult.fail("添加失败");
        }
    }

    @Override
    public JsonResult update(WarehouseProductVariety warehouseProductVariety) {
        JsonResult jsonResult = new JsonResult<>();
        if (ObjectUtil.isNotEmpty(warehouseProductVariety)){
//        WarehouseProductVariety warehouseProductVariety = new WarehouseProductVariety();
//        CopyOptions copyOptions = CopyOptions.create()
//                .setEditable(WarehouseProductVariety.class)
//                .setIgnoreError(true)
//                .setIgnoreNullValue(true);
//        BeanUtil.copyProperties(warehouseProductVarietyForm, warehouseProductVariety,copyOptions);
        baseMapper.updateById(warehouseProductVariety);
            return jsonResult.success("修改成功");
        }else {
            return jsonResult.fail("修改失败");
        }
    }


    @Override
    public JsonResult deleteWarehouseProductVariety (Long warehouseProductVarietyId){
        JsonResult jsonResult = new JsonResult<>();
        if (warehouseProductVarietyId != null){
            WarehouseProductVariety warehouseProductVariety = this.getById(warehouseProductVarietyId);
            warehouseProductVariety.setIsDeleted(true);
            baseMapper.updateById(warehouseProductVariety);
            return jsonResult.success("删除成功");
        }else {
            return jsonResult.fail("删除失败");
        }
    }
}
